{% extends 'todo/base.html' %}

{% block content %}
    <h2>分类管理</h2>
    <form method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <button type="submit">添加分类</button>
    </form>
    
    <h3>现有分类</h3>
    <ul>
        {% for category in categories %}
            <li>
                {{ category.name }} 
                <a href="{% url 'filter_by_category' category.id %}">查看任务</a>
                <form action="{% url 'delete_category' category.id %}" method="post" style="display: inline;">
                    {% csrf_token %}
                    <button type="submit" onclick="return confirm('确定要删除这个分类吗？')">删除</button>
                </form>
            </li>
        {% endfor %}
    </ul>
    
    <a href="{% url 'index' %}">返回首页</a>
{% endblock %}